import request from '@/utils/request';
import type { Key } from 'react';
import type {
  GetHospitalSetListParams,
  GetHospitalSetListResponse,
  HospitalItem,
  ReqAddHospitalParams,
  ReqUpdateHospitalParams,
} from './types';

enum ApiPath {
  GetHospitalSetList = '/admin/hosp/hospitalSet',
  AddHospital = '/admin/hosp/hospitalSet/save',
  GetHospitalItem = '/admin/hosp/hospitalSet/get',
  UpdateHospital = '/admin/hosp/hospitalSet/update',
  DeleteHospital = '/admin/hosp/hospitalSet/remove',
  BatchDeleteHospitals = '/admin/hosp/hospitalSet/batchRemove',
}

/* 
包含医院设置相关接口请求函数
*/
export const reqGetHospitalSetList = ({
  page,
  limit,
  hosname,
  hoscode,
}: GetHospitalSetListParams) => {
  return request.get<any, GetHospitalSetListResponse>(
    `${ApiPath.GetHospitalSetList}/${page}/${limit}`,
    {
      params: { hosname, hoscode },
    }
  );
};

/* 
POST /admin/hosp/hospitalSet/save
{"hosname":"ghgh","hoscode":"jhjh22","apiUrl":"a","contactsName":"a","contactsPhone":"13412341234"}
添加医院
*/
export const reqAddHospital = (hospital: ReqAddHospitalParams) => {
  return request.post<any, null>(ApiPath.AddHospital, hospital);
};

/* 
GET /admin/hosp/hospitalSet/get/{id}
获取医院
*/
export const reqGetHospitalItem = (id: number) => {
  return request.get<any, HospitalItem>(`${ApiPath.GetHospitalItem}/${id}`);
};

/* 
PUT /admin/hosp/hospitalSet/update
修改医院
*/
export const reqUpdateHospital = (hospital: ReqUpdateHospitalParams) => {
  return request.put<any, null>(ApiPath.UpdateHospital, hospital);
};

/* 
DELETE /admin/hosp/hospitalSet/remove/{id}
删除医院
*/
export const reqDeleteHospital = (id: number) => {
  return request.delete<any, null>(`${ApiPath.DeleteHospital}/${id}`);
};

/* 
DELETE /admin/hosp/hospitalSet/batchRemove
idList以请求体的形式传过去
批量删除
*/
export const reqBatchDeleteHospitals = (idList: Key[]) => {
  return request.delete<any, null>(ApiPath.BatchDeleteHospitals, {
    data: idList, // 请求体参数
  });
};